package org.smile.orm.ddl;

import org.smile.db.Dialect;
import org.smile.db.meta.TableMetaInfo;
import org.smile.db.meta.TableMetaUtil;
import org.smile.orm.OrmApplication;

import javax.sql.DataSource;
import java.sql.SQLException;

public class TableDDL {

    /**需要操作的数据源*/
    private DataSource ds;

    /**数据库方言*/
    private Dialect dialect;

    private AutoDdlType ddlType;

    TableMetaUtil util;

    public TableDDL(DataSource ds, Dialect dialect,AutoDdlType ddlType){
        this.dialect=dialect;
        this.util=new TableMetaUtil(ds);
        this.util.setDialect(dialect);
        this.ddlType=ddlType;
    }

    /***
     * 执行一个应用的定义语句
     * @param application
     */
    public void executeDDL(OrmApplication application){
        if(this.ddlType.equals(AutoDdlType.none)){//不需要执行
            return ;
        }else if(this.ddlType.equals(AutoDdlType.create)){
            //重新创建
        }else if(this.ddlType.equals(AutoDdlType.update)){
            //更新创建

        }
    }


    public TableMetaInfo getTableMetaInfo(String tableName) throws SQLException {
        return util.getTableMetaInfo(tableName);
    }

}
